/*
 * @Author: C.
 * @Date: 2021-12-24 16:11:12
 * @LastEditTime: 2021-12-24 16:56:08
 * @Description: file content
 */
// uni.setStorageSync("token", data.ticket);
// 面向本地的 高级LRU
 class LocalLRU{

  constructor(key,size=7){
    this.size = size
    this.key=`search-local-${key}`
    this.cache = uni.getStorageSync(this.key)||[]
  }
  put=(value)=>{
    if(this.cache.includes(value)) {
      let pos=this.cache.findIndex(str=>{
        return value==str
      })
      this.cache.splice(pos,1)
      this.cache.unshift(value)
    
    }else{
      if(this.size>this.cache.length){
        this.cache.unshift(value)
      }else{
        this.cache.unshift(value)
        this.cache.pop()
      }
    }
    uni.setStorageSync(this.key, this.cache);
  }
  clear=()=>{
    uni.setStorageSync(this.key, []);
  }

}
export default LocalLRU